﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using VAdvantage.Classes;
using System.Linq;

namespace VAdvantage.DataBase
{
    public class GlobalVariable
    {



        public static string ACCESSKEY = "caff4eb4fbd6273e37e8a325e19f0991";
        private static char QUOTE = '\'';
        public static bool IsVisualEditor;

        public static string PRODUCT_NAME = "ViennaAdvantage";
        public const string ASSEMBLY_NAME = "VAdvantage";

        //public static int SC_IMAGECOUNT = 5;

        public static long DateTimeOffSet = 0;

        #region Style Properties


        /// <summary>
        /// _MESSAGE_BACK_COLOR contains back color of UserControl
        /// by Karan
        /// </summary>
        private static System.Windows.Media.Color _MESSAGE_BACK_COLOR = System.Windows.Media.Colors.White;
        public static System.Windows.Media.Color MESSAGE_BACK_COLOR
        {
            get { return GlobalVariable._MESSAGE_BACK_COLOR; }
                    
        }

             


        /// <summary>
        /// _WINDOW_BACKGROUNG_COLOR contains back color of window
        /// </summary>
        //private static System.Windows.Media.Color _WINDOW_BACK_COLOR = System.Windows.Media.ColorTranslator.FromHtml("#FFFFFF");
        private static System.Windows.Media.Color _WINDOW_BACK_COLOR = System.Windows.Media.Colors.Transparent;
        //private static System.Windows.Media.Color _WINDOW_BACK_COLOR = System.Windows.Media.ColorTranslator.FromHtml("#E7E3E3");
        public static System.Windows.Media.Color WINDOW_BACK_COLOR
        {
            get { return GlobalVariable._WINDOW_BACK_COLOR; }

        }
        /// <summary>
        /// _MANDATORY_TEXT contains back color opyof tEXTBOX WHICH IS MENDATORY
        /// </summary>
        //# private static System.Windows.Media.Color _MANDATORY_TEXT_BACK_COLOR = System.Windows.Media.ColorTranslator.FromHtml("#FFB6C1");
        private static System.Windows.Media.Color _MANDATORY_TEXT_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 250, 200, 210);
        public static System.Windows.Media.Color MANDATORY_TEXT_BACK_COLOR
        {
            get { return GlobalVariable._MANDATORY_TEXT_BACK_COLOR; }
        }

        private static System.Windows.Media.Color _STATUSBAR_BACK_COLOR = System.Windows.Media.Colors.White;
        public static System.Windows.Media.Color STATUSBAR_BACK_COLOR
        {
            get { return _STATUSBAR_BACK_COLOR; }
        }

        private static System.Windows.Media.Color _STATUSBAR_LABEL_FORE_COLOR = System.Windows.Media.Colors.Black;
        public static System.Windows.Media.Color STATUSBAR_LABEL_FORE_COLOR
        {
            get { return _STATUSBAR_LABEL_FORE_COLOR; }
        }


        /// <summary>
        /// _NORMAL_TEXT contains back color of tEXTBOX WHICH IS MENDATORY
        /// </summary>
        private static System.Windows.Media.Color _NORMAL_TEXT_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 255, 255, 255);

        public static System.Windows.Media.Color NORMAL_TEXT_BACK_COLOR
        {
            get { return GlobalVariable._NORMAL_TEXT_BACK_COLOR; }
        }

        /// <summary>
        /// ReadOnly Text
        /// </summary>
        private static System.Windows.Media.Color _READONLY_TEXT_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 211, 211, 211);//Translator.FromHtml("#ece9d8");


        public static System.Windows.Media.Color READONLY_TEXT_BACK_COLOR
        {
            get { return GlobalVariable._READONLY_TEXT_BACK_COLOR; }
        }

        /// <summary>
        /// _CMB_BORDER_COLOR contains border color of combobox        /// </summary>
        private static System.Windows.Media.Color _CMB_BORDER_COLOR = System.Windows.Media.Color.FromArgb(255, 197, 214, 252);//Translator.FromHtml("#C5D6FC");

        public static System.Windows.Media.Color CMB_BORDER_COLOR
        {
            get { return GlobalVariable._CMB_BORDER_COLOR; }
        }

        /// <summary>
        /// _MANDATORY_TEXT contains back color of tEXTBOX WHICH IS MENDATORY
        /// </summary>
        //private static System.Windows.Forms.FormBorderStyle _FORM_BORDER_STYLE = System.Windows.Forms.FormBorderStyle.Sizable;

        //public static System.Windows.Forms.FormBorderStyle FORM_BORDER_STYLE
        //{
        //    get { return GlobalVariable._FORM_BORDER_STYLE; }

        //}

        /// <summary>
        /// _FORE_COLOR contains fore color of text and label
        /// </summary>
        private static System.Windows.Media.Color _FORE_COLOR = System.Windows.Media.Colors.Black;//Translator.FromHtml("#000000");

        public static System.Windows.Media.Color FORE_COLOR
        {
            get { return GlobalVariable._FORE_COLOR; }

        }

        /// <summary>
        /// CMB_BACK_COLOR contains fore color of text and label
        /// </summary>
        private static System.Windows.Media.Color _CMB_BACK_COLOR = System.Windows.Media.Colors.White;

        public static System.Windows.Media.Color CMB_BACK_COLOR
        {
            get { return GlobalVariable._CMB_BACK_COLOR; }

        }
        /// <summary>
        /// _MENU_BACK_COLOR contains back color of menustrip
        /// </summary>
        private static System.Windows.Media.Color _MENU_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 186, 210, 249);//Translator.FromHtml("#BAD2F9");

        public static System.Windows.Media.Color MENU_BACK_COLOR
        {
            get { return GlobalVariable._MENU_BACK_COLOR; }

        }
        /// <summary>
        /// _MENUITEM_BACK_COLOR contains back color of menustrip item
        /// </summary>
        private static System.Windows.Media.Color _MENUITEM_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 171, 198, 238);//Translator.FromHtml("#ABC2EE");

        public static System.Windows.Media.Color MENUITEM_BACK_COLOR
        {
            get { return GlobalVariable._MENUITEM_BACK_COLOR; }

        }

        #region AD_Tab Setting

        /// <summary>
        /// _TAB_BACK_COLOR contains back color of VTabColor #D7D7D7 #C2D5FC #A9A9A9
        /// </summary>
        private static System.Windows.Media.Color _TAB_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 231, 227, 227);//Translator.FromHtml("#E7E3E3");

        public static System.Windows.Media.Color TAB_BACK_COLOR
        {
            get { return GlobalVariable._TAB_BACK_COLOR; }

        }

        /// <summary>
        /// _SELECTED_TAB_BACK_COLOR contains back color of selected tab of VTabColor  #EFF3F7
        /// </summary>
        private static System.Windows.Media.Color _SELECTED_TAB_BACK_COLOR = System.Windows.Media.Colors.White;//Translator.FromHtml("#FFFFFF");

        public static System.Windows.Media.Color SELECTED_TAB_BACK_COLOR
        {
            get { return GlobalVariable._SELECTED_TAB_BACK_COLOR; }

        }
        /// <summary>
        /// _SELECTED_TAB_FORE_COLOR contains back color of selected tab of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _SELECTED_TAB_FORE_COLOR = System.Windows.Media.Color.FromArgb(255, 246, 246, 246);//Translator.FromHtml("#F6F6F6");

        public static System.Windows.Media.Color SELECTED_TAB_FORE_COLOR
        {
            get { return GlobalVariable._SELECTED_TAB_FORE_COLOR; }

        }
        /// <summary>
        /// _TAB_BORDER_COLOR contains border color of VTabColor
        /// </summary>
        //#2678A6, CCC4C4
        private static System.Windows.Media.Color _TAB_BORDER_COLOR = System.Windows.Media.Color.FromArgb(255, 127, 157, 185);//Translator.FromHtml("#7F9DB9");

        public static System.Windows.Media.Color TAB_BORDER_COLOR
        {
            get { return GlobalVariable._TAB_BORDER_COLOR; }

        }
        /// <summary>
        /// _TAB_PAGE_BORDER contains back color of selected tab of VTabColor #
        /// </summary>//#E7E3E3
        private static System.Windows.Media.Color _TAB_PAGE_BORDER = System.Windows.Media.Color.FromArgb(255, 127, 157, 185);//("#7F9DB9");

        public static System.Windows.Media.Color TAB_PAGE_BORDER
        {
            get { return GlobalVariable._TAB_PAGE_BORDER; }

        }
        /// <summary>
        /// _TAB_SELECTED_BORDER contains back color of selected tab of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _TAB_SELECTED_BORDER = System.Windows.Media.Color.FromArgb(255, 127, 157, 185);//("#7F9DB9");

        public static System.Windows.Media.Color TAB_SELECTED_BORDER
        {
            get { return GlobalVariable._TAB_SELECTED_BORDER; }

        }


        //Commented for SL
        //private static VAdvantage.Controls.VTabControl.TabBorderStyle _AD_TAB_BORDER_STYLE = VAdvantage.Controls.VTabControl.TabBorderStyle.Round;

        //public static VAdvantage.Controls.VTabControl.TabBorderStyle AD_TAB_BORDER_STYLE
        //{
        //    get { return GlobalVariable._AD_TAB_BORDER_STYLE; }

        //}
        /// <summary>
        /// _TAB_CROSSLINE_COLOR contains back color of menustrip item
        /// </summary>
        private static System.Windows.Media.Color _TAB_CROSSLINE_COLOR = System.Windows.Media.Color.FromArgb(255, 246, 246, 246);//("#F6F6F6");

        public static System.Windows.Media.Color TAB_CROSSLINE_COLOR
        {
            get { return GlobalVariable._TAB_CROSSLINE_COLOR; }
        }

        //Commented for SL
        //private static VAdvantage.Controls.VTabControl.TabControlDisplayManager _AD_TAB_DISPLAY_MANAGER = VAdvantage.Controls.VTabControl.TabControlDisplayManager.Custom;

        //public static VAdvantage.Controls.VTabControl.TabControlDisplayManager AD_TAB_DISPLAY_MANAGER
        //{
        //    get { return GlobalVariable._AD_TAB_DISPLAY_MANAGER; }
        //}

        #endregion


        #region " Fix Tab Properties"

        /// <summary>
        /// _TAB_BACK_COLOR contains back color of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _STATIC_TAB_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 203, 207, 215);//("#CBCFD7");

        public static System.Windows.Media.Color STATICTAB_BACK_COLOR
        {
            get { return GlobalVariable._STATIC_TAB_BACK_COLOR; }

        }

        /// <summary>
        /// _SELECTED_TAB_BACK_COLOR contains back color of selected tab of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _STATIC_SELECTED_TAB_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 239, 243, 247);//("#EFF3F7");

        public static System.Windows.Media.Color STATICSELECTED_TAB_BACK_COLOR
        {
            get { return GlobalVariable._STATIC_SELECTED_TAB_BACK_COLOR; }

        }
        /// <summary>
        /// _SELECTED_TAB_FORE_COLOR contains back color of selected tab of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _STATIC_SELECTED_TAB_FORE_COLOR = System.Windows.Media.Color.FromArgb(255, 238, 238, 238);//("#EEEEEE");

        public static System.Windows.Media.Color STATICSELECTED_TAB_FORE_COLOR
        {
            get { return GlobalVariable._STATIC_SELECTED_TAB_FORE_COLOR; }

        }
        /// <summary>
        /// _TAB_BORDER_COLOR contains border color of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _STATIC_TAB_BORDER_COLOR = System.Windows.Media.Color.FromArgb(255, 38, 120, 166);//("#2678A6");

        public static System.Windows.Media.Color STATICTAB_BORDER_COLOR
        {
            get { return GlobalVariable._STATIC_TAB_BORDER_COLOR; }

        }
        /// <summary>
        /// _TAB_PAGE_BORDER contains back color of selected tab of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _STATIC_TAB_PAGE_BORDER = System.Windows.Media.Color.FromArgb(255, 38, 120, 166);//("#2678A6");

        public static System.Windows.Media.Color STATICTAB_PAGE_BORDER
        {
            get { return GlobalVariable._STATIC_TAB_PAGE_BORDER; }

        }
        /// <summary>
        /// _TAB_SELECTED_BORDER contains back color of selected tab of VTabColor
        /// </summary>
        private static System.Windows.Media.Color _STATIC_TAB_SELECTED_BORDER = System.Windows.Media.Color.FromArgb(255, 38, 120, 166);//("#2678A6");

        public static System.Windows.Media.Color STATICTAB_SELECTED_BORDER
        {
            get { return GlobalVariable._STATIC_TAB_SELECTED_BORDER; }

        }
        /// <summary>
        /// _TAB_BORDER_STYLE contains border style of VTabControl
        /// </summary>
        //commented for SL
        //private static VTabControl.VTabControl.TabBorderStyle _STATIC_TAB_BORDER_STYLE = VTabControl.VTabControl.TabBorderStyle.Round;

        //public static VTabControl.VTabControl.TabBorderStyle STATICTAB_BORDER_STYLE
        //{
        //    get { return GlobalVariable._STATIC_TAB_BORDER_STYLE; }

        //}
        /// <summary>
        /// _TAB_CROSSLINE_COLOR contains back color of menustrip item
        /// </summary>
        private static System.Windows.Media.Color _STATIC_TAB_CROSSLINE_COLOR = System.Windows.Media.Color.FromArgb(255, 246, 246, 246);//("#F6F6F6");

        public static System.Windows.Media.Color STATICTAB_CROSSLINE_COLOR
        {
            get { return GlobalVariable._STATIC_TAB_CROSSLINE_COLOR; }

        }
        //commented for SL
        //private static VTabControl.VTabControl.TabControlDisplayManager _TAB_DISPLAY_MANAGER = VTabControl.VTabControl.TabControlDisplayManager.Custom;
        //public static VTabControl.VTabControl.TabControlDisplayManager TAB_DISPLAY_MANAGER
        //{
        //    get { return GlobalVariable._TAB_DISPLAY_MANAGER; }
        //}

        ///// <summary>
        ///// Sets the Background color of Tabs used in application.
        ///// </summary>
        ////public static void SetStaticTabProperty(VTabControl.VTabControl vTab)
        ////{
        ////    vTab.TabBackColor = STATICTAB_BACK_COLOR;
        ////    vTab.SelectedTabBackColor = STATICSELECTED_TAB_BACK_COLOR;
        ////    vTab.SelectedTabForeColor = STATICSELECTED_TAB_FORE_COLOR;
        ////    vTab.TabBorderColor = STATICTAB_BORDER_COLOR;
        ////    vTab.TabBordersStyle = STATICTAB_BORDER_STYLE;
        ////    vTab.CrossLineColor = STATICTAB_CROSSLINE_COLOR;
        ////    vTab.TabPageBorder = STATICTAB_PAGE_BORDER;
        ////    vTab.TabSelectedBorder = STATICTAB_SELECTED_BORDER;
        ////}
        #endregion


        #region Tree Setting
        /// <summary>
        /// _TREE_LINECOLOR contains line color of VTree
        /// </summary>
        private static System.Windows.Media.Color _TREE_LINECOLOR = System.Windows.Media.Color.FromArgb(255, 221, 232, 246);//("#DDE8F6");

        public static System.Windows.Media.Color TREE_LINECOLOR
        {
            get { return GlobalVariable._TREE_LINECOLOR; }

        }
        /// <summary>
        /// _TREE_LINECOLOR contains line color of VTree
        /// </summary>
        private static System.Windows.Media.Color _TREE_PANELCOLOR = System.Windows.Media.Color.FromArgb(255, 198, 218, 241);//("#C6DAF1");

        public static System.Windows.Media.Color TREE_PANELCOLOR
        {
            get { return GlobalVariable._TREE_PANELCOLOR; }

        }
        #endregion


        /// <summary>
        /// _GRID_BACK_COLOR contains back color of datagrid item
        /// </summary>
        private static System.Windows.Media.Color _GRID_BACK_COLOR = System.Windows.Media.Color.FromArgb(255, 246, 246, 246);//("#F6F6F6");

        public static System.Windows.Media.Color GRID_BACK_COLOR
        {
            get { return GlobalVariable._GRID_BACK_COLOR; }
        }

        /// <summary>
        /// _GRID_HEADERBACK_COLOR contains back color of datagrid header item
        /// </summary>
        private static System.Windows.Media.Color _GRID_HEADERBACK_COLOR = System.Windows.Media.Color.FromArgb(255, 211, 211, 211);//("#D3D3D3");

        public static System.Windows.Media.Color GRID_HEADERBACK_COLOR
        {
            get { return GlobalVariable._GRID_HEADERBACK_COLOR; }
        }

        /// <summary>
        /// _GRID_HEADERFORE_COLOR contains fore color of datagrid header item
        /// </summary>
        private static System.Windows.Media.Color _GRID_HEADERFORE_COLOR = System.Windows.Media.Color.FromArgb(255, 211, 211, 211);//("#000000");

        public static System.Windows.Media.Color GRID_HEADERFORE_COLOR
        {
            get { return GlobalVariable._GRID_HEADERFORE_COLOR; }
        }

        /// <summary>
        /// _GRID_SELECTEDBACK_COLOR contains back color of selected item in datagrid item
        /// </summary>
        private static System.Windows.Media.Color _GRID_SELECTEDBACK_COLOR = System.Windows.Media.Color.FromArgb(255, 220, 220, 220);//("#DCDCDC");

        public static System.Windows.Media.Color GRID_SELECTEDBACK_COLOR
        {
            get { return GlobalVariable._GRID_SELECTEDBACK_COLOR; }
        }

        /// <summary>
        /// _GRID_SELECTEDFORE_COLOR contains fore color of selected item in datagrid item
        /// </summary>
        private static System.Windows.Media.Color _GRID_SELECTEDFORE_COLOR = System.Windows.Media.Color.FromArgb(255, 52, 69, 85);//("#344555");

        public static System.Windows.Media.Color GRID_SELECTEDFORE_COLOR
        {
            get { return GlobalVariable._GRID_SELECTEDFORE_COLOR; }
        }

        /// <summary>
        /// _GRID_LINE_COLOR contains color of lines in datagrid
        /// </summary>
        private static System.Windows.Media.Color _GRID_LINE_COLOR = System.Windows.Media.Color.FromArgb(255, 152, 154, 147);//("#989A93");

        public static System.Windows.Media.Color GRID_LINE_COLOR
        {
            get { return GlobalVariable._GRID_LINE_COLOR; }
        }

        /// <summary>
        /// _GRID_DEFAULTBACK_COLOR contains default row back color of datagrid, 
        /// </summary>
        private static System.Windows.Media.Color _GRID_DEFAULTBACK_COLOR = System.Windows.Media.Color.FromArgb(255, 255, 255, 255);//("#FFFFFF");

        public static System.Windows.Media.Color GRID_DEFAULTBACK_COLOR
        {
            get
            {
                return GlobalVariable._GRID_DEFAULTBACK_COLOR;


            }


        }

        /// <summary>
        /// _GRID_DEFAULTBACK_COLOR contains default row back color of datagrid
        /// </summary>
        private static System.Windows.Media.Color _GRID_DEFAULTDISABLE_COLOR = System.Windows.Media.Color.FromArgb(255, 211, 211, 211);//("#EBE8E3");

        public static System.Windows.Media.Color GRID_DEFAULTDISABLEBACK_COLOR
        {
            get { return GlobalVariable._GRID_DEFAULTDISABLE_COLOR; }
        }




        private static System.Windows.Media.Color _GRID_DEFAULTALTERNATEBACK_COLOR = System.Windows.Media.Color.FromArgb(245, 245, 255, 250);//("#FFFFFF");
        public static System.Windows.Media.Color GRID_DEFAULTALTERNATEBACK_COLOR
        {
            get { return GlobalVariable._GRID_DEFAULTALTERNATEBACK_COLOR; }
        }

        /// <summary>
        /// _GRID_DEFAULTFORE_COLOR contains default row fore color of datagrid
        /// </summary>
        private static System.Windows.Media.Color _GRID_DEFAULTFORE_COLOR = System.Windows.Media.Color.FromArgb(255, 0, 0, 0);//("#000000");

        public static System.Windows.Media.Color GRID_DEFAULTFORE_COLOR
        {
            get { return GlobalVariable._GRID_DEFAULTFORE_COLOR; }
        }

        /// <summary>
        /// _GRID_DISABLEDROWBACK_COLOR contains disabled row back color of datagrid
        /// </summary>
        private static System.Windows.Media.Color _GRID_DISABLEDROWBACK_COLOR = System.Windows.Media.Colors.LightGray;

        public static System.Windows.Media.Color GRID_DISABLEDROWBACK_COLOR
        {
            get { return GlobalVariable._GRID_DISABLEDROWBACK_COLOR; }
        }

        /// <summary>
        /// _GRID_DISABLEDROWFORE_COLOR contains disabled row fore color of datagrid
        /// </summary>
        private static System.Windows.Media.Color _GRID_DISABLEDROWFORE_COLOR = System.Windows.Media.Color.FromArgb(255, 0, 0, 0);//("#000000");

        public static System.Windows.Media.Color GRID_DISABLEDROWFORE_COLOR
        {
            get { return GlobalVariable._GRID_DISABLEDROWFORE_COLOR; }
        }

        #endregion
        public static String TO_STRING(String txt)
        {
            return TO_STRING(txt, 0);
        }   //  TO_STRING

        /**
         *	Package Strings for SQL command in quotes.
         *  <pre>
         *		-	include in ' (single quotes)
         *		-	replace ' with ''
         *  </pre>
         *  @param txt  String with text
         *  @param maxLength    Maximum Length of content or 0 to ignore
         *  @return escaped string for insert statement (NULL if null)
         */
        public static String TO_STRING(String txt, int maxLength)
        {
            if (string.IsNullOrEmpty(txt))
                return "NULL";

            //  Length
            String text = txt;
            if (maxLength != 0 && text.Length > maxLength)
                text = txt.Substring(0, maxLength);

            //  copy characters		(we need to look through anyway)
            StringBuilder outt = new StringBuilder();
            outt.Append(QUOTE);		//	'
            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];
                if (c == QUOTE)
                    outt.Append("''");
                else
                    outt.Append(c);
            }
            outt.Append(QUOTE);		//	'
            //
            return outt.ToString();
        }	//	TO_STRING



        private static bool _isVserver = false;
        /// <summary>
        /// Property used in Visual Editor From
        /// </summary>
        public static bool IsVserver
        {
            get
            {
                return _isVserver;
            }
            set
            {
                _isVserver = value;
            }
        }
        public static String TO_DATE(DateTime? day)
        {
            return TO_DATE(day, true);
        }

        public static String TO_CHAR(String columnName, int displayType, String AD_Language)
        {
            StringBuilder retValue = new StringBuilder("TRIM(TO_CHAR(");
            if (DatabaseType.IsOracle)
            {
                retValue.Append(columnName);

                //  Numbers
                if (DisplayType.IsNumeric(displayType))
                {
                    if (displayType == DisplayType.Amount)
                        retValue.Append(",'9G999G990D00'");
                    else
                        retValue.Append(",'TM9'");
                    //  TO_CHAR(GrandTotal,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')
                    //if (!Language.isDecimalPoint(AD_Language))      //  reversed
                    //    retValue.append(",'NLS_NUMERIC_CHARACTERS='',.'''");
                }
                else if (DisplayType.IsDate(displayType))
                {
                    retValue.Append(",'")
                        .Append("yyyy-MM-dd")
                        .Append("'");
                }
                retValue.Append("))");
                //
                return retValue.ToString();
            }
            else if (DatabaseType.IsPostgre)
            {
                //StringBuilder retValue = new StringBuilder("TRIM(TO_CHAR(");
                retValue.Append(columnName);

                //  Numbers
                if (DisplayType.IsNumeric(displayType))
                {
                    if (displayType == DisplayType.Amount)
                        retValue.Append(",'9G999G990D00'");
                    //jz no TM9 format to EDB 
                    //else
                    //	retValue.append(",'TM9'");
                    //  TO_CHAR(GrandTotal,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')
                    //if (!Language.isDecimalPoint(AD_Language))      //jz EDB not supported  reversed
                    //	retValue.append(",'NLS_NUMERIC_CHARACTERS='',.'''");
                }
                else if (DisplayType.IsDate(displayType))
                {
                    retValue.Append(",'")
                        .Append("yyyy-MM-dd")
                        .Append("'");
                }
                retValue.Append("))");
                //
                return retValue.ToString();
            }

            return retValue.ToString();
        }   //  TO_CHAR


        public static DateTime? SetDateTimeUTC(DateTime? dateTime)
        {
            if (dateTime != null)
            {
                if (dateTime.Value.Kind == DateTimeKind.Unspecified)
                {
                    dateTime = new DateTime(dateTime.Value.Ticks,DateTimeKind.Local);// .ToUniversalTime().ToLocalTime().ToUniversalTime();
                    dateTime = dateTime.Value.ToUniversalTime();
                }
                else if (dateTime.Value.Kind == DateTimeKind.Local)
                {
                    dateTime = dateTime.Value.ToUniversalTime();
                }

            }
            return dateTime;
        }

        public static String TO_DATE(DateTime? time, bool dayOnly)
        {
            if (!dayOnly)
            {
                time = SetDateTimeUTC(time);
            }


            StringBuilder dateString = new StringBuilder("");
            string myDate = "";
            if (DatabaseType.IsOracle)
            {
                if (time == null)
                {
                    if (dayOnly)
                        return "TRUNC(SysDate)";
                    return "SysDate";
                }

                dateString = new StringBuilder("TO_DATE('");
                //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
                //String myDate = time.ToString("yyyy-mm-dd");
                //myDate = time.ToString("yyyy-MM-dd HH:mm:ss");
                myDate = time.Value.ToString();//"yyyy-MM-dd");
                if (dayOnly)
                {
                    myDate = time.Value.ToString("yyyy-MM-dd");
                    dateString.Append(myDate);
                    dateString.Append("','YYYY-MM-DD')");
                }
                else
                {
                    myDate = time.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    dateString.Append(myDate);	//	cut off miliseconds
                    dateString.Append("','YYYY-MM-DD HH24:MI:SS')");
                }
            }
            else if (DatabaseType.IsPostgre)
            {
                if (time == null)
                {
                    if (dayOnly)
                        return "TRUNC(SysDate)";
                    return "SysDate";
                }

                dateString = new StringBuilder("TO_DATE('");
                //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
                if (dayOnly)
                {
                    myDate = time.Value.ToString("yyyy-MM-dd");
                    dateString.Append(myDate);
                    dateString.Append("','YYYY-MM-DD')");
                }
                else
                {
                    myDate = time.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    dateString.Append(myDate);	//	cut off miliseconds
                    dateString.Append("','YYYY-MM-DD HH24:MI:SS')");
                }
            }
            else if (DatabaseType.IsMSSql)
            {
                if (time == null)
                {
                    if (dayOnly)
                        return "CAST(STR(YEAR(Getdate()))+'-'+STR(Month(Getdate()))+'-'+STR(Day(Getdate())) AS DATETIME)";
                    return "getdate()";
                }

                dateString = new StringBuilder("CAST('");
                //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
                myDate = time.ToString();
                if (dayOnly)
                {
                    dateString.Append(myDate.Substring(0, 10));
                    dateString.Append("' AS DATETIME)");
                }
                else
                {
                    dateString.Append(myDate.Substring(0, myDate.IndexOf(".")));	//	cut off miliseconds
                    dateString.Append("' AS DATETIME)");
                }
            }
            return dateString.ToString();
        }





        internal static string SetDateFormat(DateTime time, bool dayOnly)
        {
            string myDate = "";
            if (DatabaseType.IsOracle)
            {
                if (time == null)
                {
                    if (dayOnly)
                        return DateTime.Now.ToString("yyyy-MM-dd");
                    return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }

                //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
                //String myDate = time.ToString("yyyy-mm-dd");
                if (dayOnly)
                {
                    myDate = time.ToString("yyyy-MM-dd");
                }
                else
                {
                    myDate = time.ToString("yyyy-MM-dd HH:mm:ss");
                }
            }
            else if (DatabaseType.IsPostgre)
            {
                if (time == null)
                {
                    if (dayOnly)
                        return "TRUNC(SysDate)";
                    return "SysDate";
                }

                //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
                myDate = time.ToString("yyyy-MM-dd HH:mm:ss");
                if (dayOnly)
                {
                    myDate = time.ToString("yyyy-MM-dd");
                }
                else
                {
                    myDate = time.ToString("yyyy-MM-dd HH:mm:ss");
                }
            }
            //else if (DatabaseType.IsMSSql)
            //{
            //    if (time == null)
            //    {
            //        if (dayOnly)
            //            return "CAST(STR(YEAR(Getdate()))+'-'+STR(Month(Getdate()))+'-'+STR(Day(Getdate())) AS DATETIME)";
            //        return "getdate()";
            //    }

            //    //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
            //    myDate = time.ToString();
            //    if (dayOnly)
            //    {
            //        dateString.Append(myDate.Substring(0, 10));
            //        dateString.Append("' AS DATETIME)");
            //    }
            //    else
            //    {
            //        dateString.Append(myDate.Substring(0, myDate.IndexOf(".")));	//	cut off miliseconds
            //        dateString.Append("' AS DATETIME)");
            //    }
            //}
            return myDate;
        }
        /// <summary>
        /// _AD_LANGUAGE variable contains the currently selected Language
        /// </summary>
        private static string _AD_LANGUAGE;
        /// <summary>
        /// Gets or Sets get the value of static variable _AD_LANGUAGE
        /// </summary>
        public static string AD_LANGUAGE
        {
            get { return GlobalVariable._AD_LANGUAGE; }
            set { GlobalVariable._AD_LANGUAGE = value; }
        }
        #region "Calendar Variables"
        // used in workflow
        public static int Minute = 12;
        public static int Second = 13;
        public static int Hour = 10;
        public static int DayOfMonth = 5;
        public static int DayOfYear = 6;
        public static int Month = 2;
        public static int Year = 1;
       

        #endregion


        #region BaseLanguage


        /// <summary>
        /// _AD_BASE_LANGUAGE variable contains the default Language english(en-EN)
        /// </summary>
        private static string _AD_BASE_LANGUAGE = "en_US";
        /// <summary>
        /// Gets or Sets get the value of static variable _AD_BASE_LANGUAGE
        /// </summary>
        public static string AD_BASE_LANGUAGE
        {
            get
            {
                return GlobalVariable._AD_BASE_LANGUAGE;
            }
            //set
            //{
            //    GlobalVariable._AD_BASE_LANGUAGE ="en-US";
            //}
        }


        /// <summary>
        /// is Base Language (en-US)
        /// </summary>
        /// <returns>true if base language</returns>
        public static bool IsBaseLanguage()
        {
            return AD_BASE_LANGUAGE.Equals(Utility.Envs.GetLoginLanguage(Utility.Envs.GetContext()).GetAD_Language());
        }

       

        /// <summary>
        /// Table is in Base Translation (AD)
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static bool IsBaseTranslation(string tableName)
        {
            if (tableName.StartsWith("AD")
                || tableName.Equals("C_Country_Trl"))
                return true;
            return false;
        }	//	

        #endregion

        public static int GridRowsCount(VAdvantage.Controls.VDataGrid ctrl)
        {
            var count = 0;
            if (ctrl.ItemsSource != null)
            {
                count = ctrl.ItemsSource.OfType<object>().Count();
            }
            return count;
        }


        public static string GetLanguageCode()
        {
            return Utility.Envs.GetLoginLanguage(Utility.Envs.GetContext()).GetAD_Language();
            //if (AD_LANGUAGE != "")
            //    return    AD_LANGUAGE.Replace("-", "_");
            //else
            //    return "";
        }


        //private static int quota = 30;
        //internal static void SetQuota(int val)
        //{
        //    if (val > 30)
        //    {
        //        quota = val;
        //    }
        //}
        //internal static int GetQuota()
        //{
        //    return quota;
        //}

        /// <summary>
        /// Set Default for demo 
        /// </summary>
        /// 
        private static string _user = "";
        public static string UserName
        {
            get
            {
                return _user;
            }
            set
            {
                _user = value;
            }
        }

        private static string _pwd = "";
        public static string Pwd
        {
            get
            {
                return _pwd;
            }
            set
            {
                _pwd = value;
            }
        }
    }
}
